<?php

/*
 * File theorie.php for project Rijlesplanner.nl
 * Created on 2 dec 2007 at 21:30:23 by Ivar Pruijn
 */
class praktijk extends modules {
	// Properties:
	protected $name = "praktijk";
	protected $title = "Rijles nemen";
	protected $subtitle = "";
	protected $moduleOptions = array ();
	private $errors = array ();

	// Methods:

	/**
	 * void __construct ()
	 * This is the constructor method for this class.
	 */
	public function __construct() {
		parent :: __construct();
		$this->logger = parent :: getLogger();
		$this->user = parent :: getUser();
		$this->template = parent :: getTemplate();
	}

	/**
	 * Object process()
	 * 
	 * Processes the template and current module
	 * 
	 * @param Smarty template The Smarty template to process (sets variables etc.)
	 * @return Smarty The template that has been processed
	 */
	function process(& $template = null) {
		$this->template = $template;
		
		parent::loadModule("ads",$template);
		
		if ($this->user instanceof Visitor) {
			parent :: loadModule("authentication", $template);
		} else
			if ($this->user instanceof Leerling) {
				$this->template->assign('plantijd',((int)$_SESSION['Plantijd']) + 1);
				$this->template->assign('annuleertijd',((int)$_SESSION['Annuleertijd']) + 1);
				$this->template->assign('rijschool', array (
					'naam' => $this->user->getRijschoolNaam(),
					'id' => $this->user->getRijschoolId()
				));
			}
		if (!empty ($_POST)) {
			if (!$this->auth->accessTo($this->name, null, $_POST['action'])) {
				$this->actionAccessDenied();
			} else {
				switch ($_POST['action']) {
					case "lessenplannenblok" :
						if ($this->user instanceof Leerling) {
							$instructeurId = $_POST['instructeurId'];
							$cursusId = $_POST['cursusId'];
							if (!empty($_POST['typeId'])) {
								$typeId = $_POST['typeId'];
							} else {
								$typeId = -1;
							}	
							$dateYear = $_POST['dateYear'];
							$dateMonth =  $_POST['dateMonth'];
							$dateDay =  $_POST['dateDay'];
							$this->lessenPlannen($instructeurId, $cursusId, $typeId, $dateYear, $dateMonth, $dateDay);
							$this->template->assign('moduleTemplate', 'modules/praktijk/lessenplannen_leerling.tpl');
						}
						break;
					case "praktijkplannen" :
						if ($this->user instanceof Leerling) {
							$plannenResult = $this->planPraktijkLeerling();
							$this->template->assign('plannenResult', $plannenResult);
							$this->template->assign('moduleTemplate', 'modules/praktijk/planpraktijk_leerling.tpl');
						}
						break;
					case "praktijkannuleren" :
						if ($this->user instanceof Leerling) {
							$annulerenResult = $this->annuleerPraktijkLeerling();
							$this->template->assign('annulerenResult', $annulerenResult);
							$this->template->assign('moduleTemplate', 'modules/praktijk/annuleerpraktijk_leerling.tpl');
						}
						break;
					case "cursusoverzicht" :
						if ($this->user instanceof Leerling) {
							$cursusId = $_POST['cursusId'];
							$this->cursusOverzicht($cursusId);
							$this->template->assign('moduleTemplate', 'modules/praktijk/cursusoverzicht_leerling.tpl');
						}
						break;
					case "vorderingskaarten" :
						if ($this->user instanceof Leerling) {
							$cursusId = $_POST['cursusId'];
							$this->vorderingsKaarten($cursusId);
							$this->template->assign('moduleTemplate', 'modules/praktijk/vorderingskaarten_leerling.tpl');
						}
						break;
				}
			}
		} else
			if (!empty ($_GET['option'])) {
				if (!$this->auth->accessTo($this->name, $_GET['option'])) {
					$this->optionAccessDenied();
				} else {
					switch ($_GET['option']) {
						case "lessenplannen" :
							if ($this->user instanceof Leerling) {
								$this->lessenPlannen();
								$this->template->assign('moduleTemplate', 'modules/praktijk/lessenplannen_leerling.tpl');
							}
							break;
						case "cursusoverzicht" :
							if ($this->user instanceof Leerling) {
								$this->cursusOverzicht();
								$this->template->assign('moduleTemplate', 'modules/praktijk/cursusoverzicht_leerling.tpl');
							}
							break;
						case "vorderingskaarten" :
							if ($this->user instanceof Leerling) {
								$this->vorderingsKaarten();
								$this->template->assign('moduleTemplate', 'modules/praktijk/vorderingskaarten_leerling.tpl');
							}
							break;
						default :
							if ($this->user instanceof Visitor) {
								$this->template->assign('moduleTemplate', 'modules/praktijk/mijnpraktijk_bezoeker.tpl');
							} else if ($this->user instanceof Leerling) {
								$this->praktijkPageContent();
								$this->template->assign('moduleTemplate', 'modules/praktijk/mijnpraktijk_leerling.tpl');
							}
							break;
					}
				}
			} else {
				parent::loadModule("reviews",$template);
				if ($this->user instanceof Visitor) {
					$this->template->assign('moduleTemplate', 'modules/praktijk/mijnpraktijk_bezoeker.tpl');
				} else if ($this->user instanceof Leerling) {
					$this->praktijkPageContent();
					$this->template->assign('moduleTemplate', 'modules/praktijk/mijnpraktijk_leerling.tpl');
				}
			}
	}

	function praktijkPageContent() {
		$errors = array ();
		try {
			$result = $this->wsclient->WS_Rijlesplanner_GetContent(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'PageId' => 'praktijk'
			));
			$content = $result->Content;
			$this->template->assign('pageContent', $content);
		} catch (SoapFault $e) {
			$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})", PEAR_LOG_INFO);
			switch ($e->faultcode) {
				default :
					$errorcode = 63;
					$errormessage = 'Onbekende fout bij ophalen praktijk pagina content ("'.$e->faultstring.'")';
					break;
			}
			$errors[] = array (
				'code' => $errorcode,
				'message' => $errormessage
			);
			$this->setSubtitle($errormessage);
		}
		$this->template->assign('errors', $errors);
	}


	/**
	 * void lessenPlannen()
	 * 
	 * Shows the 'Lessen plannen' page (for a Leerling that is logged in)
	 * Sets an error array in the template in case of errors.
	 */
	function lessenPlannen($instructeurId = 0, $cursusId = 0, $typeId = 0, $dateYear=0, $dateMonth=0, $dateDay=0) {
		$this->errors = array ();
		$datum = 0;
		$date = null;
		if($dateYear <= 0 || $dateMonth <= 0 || $dateDay <= 0) {
			$date = new DateTime();
			$datum = $date->format(DATE_ISO8601);
		} else {
			$dateString = $dateYear."-".$dateMonth."-".$dateDay;
			$date = new DateTime($dateString);
			$datum = $date->format(DATE_ISO8601);
		}
		$this->logger->log("Date: " . print_r($date,true), PEAR_LOG_DEBUG);
		$this->logger->log("Datum: " . $datum, PEAR_LOG_DEBUG);
		$this->template->assign('datum',$datum);
		$this->template->assign('dateYear',$dateYear);
		$this->template->assign('dateMonth',$dateMonth);
		$this->template->assign('dateDay',$dateDay);
		
		$date->modify("-7 days");
		$datePrevWeekDay = $date->format("d");
		$datePrevWeekMonth = $date->format("m");
		$datePrevWeekYear = $date->format("Y");
		$this->template->assign('datePrevWeekDay',$datePrevWeekDay);
		$this->template->assign('datePrevWeekMonth',$datePrevWeekMonth);
		$this->template->assign('datePrevWeekYear',$datePrevWeekYear);

		$date->modify("+6 days");
		$datePrevDay = $date->format("d");
		$datePrevMonth = $date->format("m");
		$datePrevYear = $date->format("Y");
		$this->template->assign('datePrevDay',$datePrevDay);
		$this->template->assign('datePrevMonth',$datePrevMonth);
		$this->template->assign('datePrevYear',$datePrevYear);

		$date->modify("+2 days");
		$dateNextDay = $date->format("d");
		$dateNextMonth = $date->format("m");
		$dateNextYear = $date->format("Y");
		$this->template->assign('dateNextDay',$dateNextDay);
		$this->template->assign('dateNextMonth',$dateNextMonth);
		$this->template->assign('dateNextYear',$dateNextYear);

		$date->modify("+6 days");
		$dateNextWeekDay = $date->format("d");
		$dateNextWeekMonth = $date->format("m");
		$dateNextWeekYear = $date->format("Y");
		$this->template->assign('dateNextWeekDay',$dateNextWeekDay);
		$this->template->assign('dateNextWeekMonth',$dateNextWeekMonth);
		$this->template->assign('dateNextWeekYear',$dateNextWeekYear);

		try {
			// first get the list of cursussen
			$result = $this->wsclient->WS_Leerling_GetCursussen(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'LeerlingId' => $this->user->getId()
			));
			$cursussen = $result->Cursussen;
			$this->template->assign('cursussen', $cursussen);
			
			$cursusNameSelected = "";
			foreach ($cursussen AS $cursus) {
				if ($cursus->getId() == $cursusId) {
					$cursusNameSelected = $cursus->getPakketNaam();
				}
			}
			
			if ($cursusId <= 0 && count($cursussen) > 0) {
				$cursusNameSelected = $cursussen[0]->PakketNaam;
				$cursusId = $cursussen[0]->Id;
			} 

			$this->template->assign('cursusNameSelected', $cursusNameSelected);
			$this->template->assign('cursusIdSelected', $cursusId);


			$result = $this->wsclient->WS_Cursus_Overzicht(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $cursusId
			));

			// second, get the list of instructeurs
			$result = $this->wsclient->WS_Cursus_GetInstructeurs(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $cursusId
			));
			$instructeurs = $result->Instructeurs;
			if(count($instructeurs) > 0) {
				$instructeurIdSelected = 0;
				if ($instructeurId < 0) {
					$instructeurIdSelected = $instructeurs[0]->Id;
				} else {
					foreach ($instructeurs AS $instructeur) {
						if ($instructeur->getId() == $instructeurId) {
							$instructeurIdSelected = $instructeur->getId();
						}
					}
				}
			} else {
				return;
			}
			#else {
			#	$instructeur = new Instructeur();
			#	$instructeur->setId(-1);
			#	$instructeur->setNaam("Geen instructeur");
			#	$instructeurs = array(0=>$instructeur);
			#	$instructeurIdSelected = $instructeurs[0]->getId();
			# }
			
			$this->template->assign('instructeurs', $instructeurs);
			$this->template->assign('instructeurIdSelected', $instructeurIdSelected);
			
			// third, get the list of lestypes
			$result = $this->wsclient->WS_AgendaItemType_Lijst(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $cursusId
			));
			$this->logger->log(print_r($result,true),PEAR_LOG_DEBUG);
			$types = $result->Types;
			if(count($types) > 0) {
				$typeIdSelected = 1;
				$typeNameSelected = "";
				$typeMinutenSelected = 0;
				if ($typeId <= 0) {
					$typeIdSelected = $types[0]->getId();
					$typeNameSelected = $types[0]->getNaam();
					$typeMinutenSelected = $types[0]->getMinuten();
				} else {
					foreach ($types AS $type) {
						if ($type->getId() == $typeId) {
							$typeIdSelected = $type->getId();
							$typeNameSelected = $type->getNaam();
							$typeMinutenSelected = $type->getMinuten();
						}
					}
				}
			} else {
				return;
			}
			# else {
			#	
			#	$types[0] = new Object('Id', -1, 'CategorieId', 2, 'Naam', "les", "Examen", "", "Theorie", "", "Minuten", 0);
			#	$this->logger->log('Types: '  . print_r($types[0],true));
			#	$typeIdSelected = $types[0]->Id;
			#	$typeNameSelected = $types[0]->Naam;
			#	$typeMinutenSelected = $types[0]->Minuten;
			# }
			$this->template->assign('types', $types);
			$this->template->assign('typeIdSelected', $typeIdSelected);
			$this->template->assign('typeNameSelected', $typeNameSelected);
			$this->template->assign('typeMinutenSelected', $typeMinutenSelected);

			// now get the planning for this cursus
			$result = $this->wsclient->WS_AgendaItem_Lijst(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $cursusId,
				'InstructeurId' => $instructeurId,
				'Datum' => $datum
			));

			// $this->logger->log("Result for WS_AgendaItem_Lijst: " . print_r($result,true), PEAR_LOG_DEBUG);
			$beschikbaar = $result->Beschikbaar;
			// loop through this list to filter the ones that do not fit the currently selected lestype
			$beschikbaarFiltered = array();
			if(isset($beschikbaar)) {
				foreach($beschikbaar AS $b) {
					$dateStartMs = $this->timestampfromxml($b->getStart());
					$dateStopMs = $this->timestampfromxml($b->getStop());
					$minutes = ($dateStopMs-$dateStartMs)/60;
					if($minutes == $typeMinutenSelected) {
						$beschikbaarFiltered[] = $b;
					}
				}
			}
			$this->template->assign('beschikbaar', $beschikbaarFiltered);
			$reedsgepland = $result->ReedsGepland;
			$this->template->assign('reedsgepland', $reedsgepland);
			$this->template->assign('errors', $this->errors);
		} catch (SoapFault $e) {
			$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})", PEAR_LOG_INFO);
			switch ($e->faultcode) {
				case 2 :
					$errorcode = 27;
					$errormessage = 'Onbekende cursus voor deze instructeur';
					break;
				default :
					$errorcode = 16;
					$errormessage = 'Onbekende fout bij praktijk plannen ("' . $e->faultstring . '")';
					break;
			}
			$errors[] = array (
				'code' => $errorcode,
				'message' => $errormessage
			);
			$this->setSubtitle($errormessage);
			
		} catch (PraktijkPlannenException $e) {
			$errors[] = array (
				'code' => $e->getCode(),
				'message' => $e->getMessage()
			);
			$this->setSubtitle($e->getMessage());
		}

		$this->template->assign('errors', $this->errors);

	}

	/**
	 * void cursusOverzicht()
	 * 
	 * Shows the 'Cursus overzicht' page (for a Leerling that is logged in)
	 * Sets an error array in the template in case of errors.
	 */
	function cursusOverzicht($cursusId=0) {
		$this->errors = array ();
		try {
			// first get the list of cursussen
			$result = $this->wsclient->WS_Leerling_GetCursussen(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'LeerlingId' => $this->user->getId()
			));

			$cursussen = $result->Cursussen;
			$this->template->assign('cursussen', $cursussen);

			$cursusNameSelected = "";
			foreach ($cursussen AS $cursus) {
				if ($cursus->getId() == $cursusId) {
					$cursusNameSelected = $cursus->getPakketNaam();
				}
			}
			
			if ($cursusId <= 0 && count($cursussen) > 0) {
				$cursusNameSelected = $cursussen[0]->PakketNaam;
				$cursusId = $cursussen[0]->Id;
			} 

			$this->template->assign('cursusNameSelected', $cursusNameSelected);
			$this->template->assign('cursusIdSelected', $cursusId);

			$result = $this->wsclient->WS_Cursus_Overzicht(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $cursusId
			));
			$items = $result->Items;
			$this->template->assign('items', $items);
			$statistieken = $result->Statistieken;
			$this->template->assign('statistieken', $statistieken);
			# $this->logger->log("Statistieken " . print_r($statistieken,true));


		} catch (SoapFault $e) {
			$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})", PEAR_LOG_INFO);
			switch ($e->faultcode) {
				default :
					$errorcode = 36;
					$errormessage = 'Onbekende fout bij ophalen geplande cursusoverzicht ("' . $e->faultstring . '")';
					break;
			}
			$errors[] = array (
				'code' => $errorcode,
				'message' => $errormessage
			);
			$this->setSubtitle($errormessage);
		} catch (PraktijkPlannenException $e) {
			$errors[] = array (
				'code' => $e->getCode(),
				'message' => $e->getMessage()
			);
			$this->setSubtitle($e->getMessage());
		}

		$this->template->assign('errors', $this->errors);
	}

	/**
	 * void vorderingsKaarten()
	 * 
	 * Shows the 'Vorderingskaarten' page (for a Leerling that is logged in)
	 * Sets an error array in the template in case of errors.
	 */
	function vorderingsKaarten($cursusId=0) {
		$this->errors = array ();
		try {
			// first get the list of cursussen
			$result = $this->wsclient->WS_Leerling_GetCursussen(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'LeerlingId' => $this->user->getId()
			));
			//$this->logger->log(print_r($result,true),PEAR_LOG_DEBUG);
			$cursussen = $result->Cursussen;
			$this->template->assign('cursussen', $cursussen);
			$cursusNameSelected = "";
			foreach ($cursussen AS $cursus) {
				if ($cursus->getId() == $cursusId) {
					$cursusNameSelected = $cursus->getPakketNaam();
				}
			}
			
			if ($cursusId <= 0 && count($cursussen) > 0) {
				$cursusNameSelected = $cursussen[0]->PakketNaam;
				$cursusId = $cursussen[0]->Id;
			} 

			$this->template->assign('cursusNameSelected', $cursusNameSelected);
			$this->template->assign('cursusIdSelected', $cursusId);


			// Second, get the list of vorderingen
			$result = $this->wsclient->WS_Cursus_Vordering_Get(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $cursusId
			));
			$this->logger->log(print_r($result,true),PEAR_LOG_DEBUG);
			$items = array_reverse($result->Items);
			$this->template->assign('items', $items);
			$vorderingkaart = $result->VorderingKaart;
			$this->template->assign('vorderingkaart', $vorderingkaart);
			$resultaten = $result->Resultaten;
			$this->template->assign('resultaten', $resultaten);
			$notities = $result->Notities;
			$this->template->assign('notities', $notities);
			
			$smartyPaginate = new SmartyPaginate();
			// required connect
			$smartyPaginate->connect("items");
			// set items per page
			$smartyPaginate->setLimit(6,"items");
			$smartyPaginate->setUrl($_SERVER['REQUEST_URI'],"items");
			$smartyPaginate->setUrlVar("next","items");
			$smartyPaginate->setNextText("Volgende vorderingen","items");
			$smartyPaginate->setPrevText("Vorige vorderingen","items");

			// assign your db results to the template
			$smartyPaginate->setTotal(count($items),"items");
			$this->template->assign('items', array_slice($items, $smartyPaginate->getCurrentIndex("items"), $smartyPaginate->getLimit("items")));
			$this->logger->log("Aantal resultaten: ".count($items), PEAR_LOG_DEBUG);
			// assign {$paginate} var
			$smartyPaginate->assign($this->template,"paginate","items");
		} catch (SoapFault $e) {
			$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})", PEAR_LOG_INFO);
			switch ($e->faultcode) {
				default :
					$errorcode = 66;
					$errormessage = 'Onbekende fout bij ophalen vorderingskaarten ("' . $e->faultstring . '")';
					break;
			}
			$errors[] = array (
				'code' => $errorcode,
				'message' => $errormessage
			);
			$this->setSubtitle($errormessage);
		} catch (PraktijkPlannenException $e) {
			$errors[] = array (
				'code' => $e->getCode(),
				'message' => $e->getMessage()
			);
			$this->setSubtitle($e->getMessage());
		}

		$this->template->assign('errors', $this->errors);
	}

	/**
	 * void planPraktijkLeerling()
	 * 
	 * Plans a praktijk moment (for a Leerling that is logged in)
	 * Sets an error array in the template in case of errors.
	 */
	function planPraktijkLeerling() {
		$plannenresult = false;
		$errors = array ();
		try {
			if (!isset ($_POST['cursusId']) || empty ($_POST['cursusId'])) {
				throw new TheoriePlannenException('Geen cursus ID gegeven', 29);
			}
			if (!isset ($_POST['blokId']) || empty ($_POST['blokId'])) {
				throw new TheoriePlannenException('Geen blok ID gegeven', 32);
			}
			if (!isset ($_POST['typeId']) || empty ($_POST['typeId'])) {
				throw new TheoriePlannenException('Geen type ID gegeven', 30);
			}
			if (!isset ($_POST['startDateYear']) || empty ($_POST['startDateYear']) || !isset ($_POST['startDateMonth']) || empty ($_POST['startDateMonth'])  || !isset ($_POST['startDateDay']) || empty ($_POST['startDateDay'])) {
				throw new TheoriePlannenException('Geen starttijd gegeven', 33);
			}
			$dateString = $_POST['startDateYear']."-".$_POST['startDateMonth']."-".$_POST['startDateDay'];
			$date = new DateTime($dateString);
			$startDate = $date->format(DATE_ISO8601);
			$result = $this->wsclient->WS_AgendaItem_Plan(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $_POST['cursusId'],
				'BlokId' => $_POST['blokId'],
				'TypeId' => $_POST['typeId'],
				'Start' => $startDate
			));
			$plannenresult = $result->Success;
		} catch (SoapFault $e) {
			$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})", PEAR_LOG_INFO);
			switch ($e->faultcode) {
				default :
					$errorcode = 67;
					$errormessage = $e->faultstring;
					break;
			}
			$errors[] = array (
				'code' => $errorcode,
				'message' => $errormessage
			);
			$this->setSubtitle($errormessage);
		} catch (TheoriePlannenException $e) {
			$errors[] = array (
				'code' => $e->getCode(),
				'message' => $e->getMessage()
			);
			$this->setSubtitle($e->getMessage());
		}
		$this->template->assign('errors', $errors);
		return $plannenresult;
	}

	/**
	 * void annuleerPraktijkLeerling()
	 * 
	 * Cancels a praktijk moment (for a Leerling that is logged in)
	 * Sets an error array in the template in case of errors.
	 */
	function annuleerPraktijkLeerling() {
		$annulerenResult = false;
		$errors = array ();
		try {
			if (!isset ($_POST['cursusId']) || empty ($_POST['cursusId'])) {
				throw new TheorieAnnulerenException('Geen cursus ID gegeven', 34);
			}
			if (!isset ($_POST['itemId']) || empty ($_POST['itemId'])) {
				throw new TheorieAnnulerenException('Geen item ID gegeven', 35);
			}
			$result = $this->wsclient->WS_AgendaItem_Annuleer(array (
				'RijschoolId' => $this->user->getRijschoolId(),
				'SessionId' => $_SESSION['SessionId'],
				'CursusId' => $_POST['cursusId'],
				'ItemId' => $_POST['itemId']
			));

			$annulerenResult = $result->Success;
		} catch (SoapFault $e) {
			$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})", PEAR_LOG_INFO);
			switch ($e->faultcode) {
				default :
					$errorcode = 16;
					$errormessage = $e->faultstring;
					break;
			}
			$errors[] = array (
				'code' => $errorcode,
				'message' => $errormessage
			);
			$this->setSubtitle($errormessage);
		} catch (TheoriePlannenException $e) {
			$errors[] = array (
				'code' => $e->getCode(),
				'message' => $e->getMessage()
			);
			$this->setSubtitle($e->getMessage());
		}
		$this->template->assign('errors', $errors);
		return $annulerenResult;
	}

	public function addError($message, $code) {
		$this->errors[] = array (
			'code' => $code,
			'message' => $message
		);
		$this->setSubtitle($message);
	}

	public function getTitle() {
		return $this->title;
	}

	public function getSubTitle() {
		return $this->subtitle;
	}

	public function setSubTitle($newVal = "") {
		if (!empty ($newVal)) {
			$this->subtitle = $newVal;
		}
	}

	/*
	 * string __toString()
	 * 
	 * Returns a String representation of this class.
	 * 
	 * @return string A representation of this class
	 */
	public function __toString() {
		return $this->title;
	}

	private function timestampfromxml( $t ) {
    	return strtotime($t);
	}
}
?>
